<?php

namespace app\common\model;

use think\Model;

class Device extends Model
{
    // 表名
    protected $name = 'device';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'created_at';
    protected $updateTime = false;

    public function keys()
    {
        return $this->hasMany('DeviceKey');
    }

//    protected static function init()
//    {
//        self::beforeDelete(function ($row) {
//
//            $count = DeviceKey::where('device_id', $row->id)->where('status', DeviceKey::ACTIVATED)->count();
//            if ($count) {
//                return false;
//            }
//
//            DeviceKey::where('device_id', $row->id)->delete();
//        });
//    }

}